*********************************************************************************
*** Appendix A8
*********************************************************************************

* Project: 	International threats and European defense
* Authors: 	Matthias Mader
* Date:		March 2023	

* Data: VW Project, Pane-European survey (W1)

*********************************************************************************

*** Setup

	clear
	set more off            						// Disable partitioned output
	set dp period									// Use comma instead of dot for decimals
	set linesize 80         						// Line size limit to make output more readable
	macro drop _all         						// clear all macros
	set scheme plotplainblind, permanent				// set graph scheme, e.g., cleanplots, plottig, plotplainblind, burd3, s1mono
	graph set window fontface "Times New Roman"		// set font in graphs | "Arial" | "Times New Roman"


*** Table A8.1
	
	use DATA_clean, clear

	*Row 1
	reg csdp_wouldlike c.threat_ind2##c.feel_EU i.QCOUNTRY female age ib2.education iso comp mili
	margins, dydx(threat_ind2)
	margins, dydx(threat_ind2) at(feel_EU=(0 1))
	*Column 4, row 1: Interaction term (c.threat_ind2#c.feel_EU) in regression table

	*** Rows 2, 3
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##c.quizr i.QCOUNTRY female age i.education iso comp mili
	margins, dydx(threat_ind2) at(quiz=(1 0))
	margins, dydx(threat_ind2) at(feel_EU=(1 0) quiz=(1))
	margins, dydx(threat_ind2) at(feel_EU=(1 0) quiz=(0))
	*Column 4, row 2: Interaction term (c.threat_ind2#c.feel_EU) in regression table

	gen quizr2 = 1-quizr // political sophistication reversed so the interaction term (c.threat_ind2#c.feel_EU) refers to differences between the politically sophisticated
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##c.quizr2 i.QCOUNTRY female age education iso comp mili
	*Column 4, row 4:  Interaction term (c.threat_ind2#c.feel_EU) in regression table


*** Figure A8.1
	
	use DATA_clean, clear

	*Top left panel
		reg csdp_wouldlike c.threat_ind2 feel_EU i.QCOUNTRY female age ib2.education iso comp mili
		margins, at(threat_ind2=(0 (.025) 1))
		marginsplot,  ///
			name(g1, replace) ///
			recast(scatter) ///
			plotopts(mcolor(none))  ///
			ciopts(recast(rbar) barwidth(0.01)) ///
			xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
			ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
			title("") ///
			legend(off) 
		
	*Top right panel
	reg csdp_wouldlike c.threat_ind2##c.feel_EU i.QCOUNTRY female age ib2.education iso comp mili
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1))
	marginsplot,  ///
		name(g2, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.85 -0.01 "EU supporters", color(gs9) place(right) size(large)) ///
		text(0.40 -0.01  "EU opponents", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)


	*Bottom left panel
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##c.quiz i.QCOUNTRY female age ib2.education iso comp mili
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) quiz=(0))
	marginsplot,  ///
		name(g3, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.80 -0.01 "Unsophisticated EU Supporters", color(gs9) place(right) size(large)) ///
		text(0.45 -0.01  "Unsophisticated EU Opponents", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)


	*Bottom right panel
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##c.quiz i.QCOUNTRY female age ib2.education iso comp mili // (same as above)
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) quiz=(4))
	marginsplot,  ///
		name(g4, replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(0.85 -0.01 "Sophisticated EU Supporters", color(gs9) place(right) size(large)) ///
		text(0.40 -0.01  "Sophisticated EU Opponents", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ///
		xtitle("Threat perception", size(large)) xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("Support for integration", size(large)) yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		legend(off)



*** Table A8.2
	
	use DATA_clean, clear

	*** Column 1

	forvalues val = 1/25 {
	reg csdp_wouldlike c.threat_ind2 c.feel_EU female age ib2.education iso comp mili if QCOUNTRY==`val'
	estimates store m`val'
}

	***Columns 2, 3

	forvalues val = 1/25 {
	reg csdp_wouldlike c.threat_ind2##c.feel_EU female age ib2.education iso comp mili if QCOUNTRY==`val'
	estimate store m`val'
}
	forvalues val = 1/25 {
	estimate restore m`val'
	margins, dydx(threat_ind2) at(feel_EU=(0 1))
}



*** Figure A8.2
	
	use DATA_clean, clear

	***Austria for labels
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##i.QCOUNTRY female age education iso comp mili
	foreach val in 1 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		text(.90 -0.01 "EU supporters", color(gs9) place(right) size(large)) ///
		text(0.37 -0.01  "EU opponents", color(gs0) place(right) size(large)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	***All other countries
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##i.QCOUNTRY female age education iso comp mili
	foreach val in 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid labcolor(white)) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	***All other countries
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##i.QCOUNTRY female age education iso comp mili
	foreach val in 6 11 16 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid) ///
		xlab(, nogrid labcolor(white)) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	***All other countries
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##i.QCOUNTRY female age education iso comp mili
	foreach val in 21 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid) ///
		xlab(, nogrid) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}
	***All other countries
	reg csdp_wouldlike c.threat_ind2##c.feel_EU##i.QCOUNTRY female age education iso comp mili
	foreach val in 22 23 24 25 {
	local v : label (QCOUNTRY) `val'
	margins, at(threat_ind2=(0 (.025) 1) feel_EU=(0 1) QCOUNTRY=(`val'))
	marginsplot,  ///
		name(c`val', replace) ///
		recast(scatter) ///
		plot1opts(mcolor(none)) plot2opts(mcolor(none)) ///
		ciopts(recast(rbar) barwidth(0.01)) ci1opts(color(gs0) alcolor(none)) ci2opts(color(gs9%80) alcolor(none)) ///
		ylab(, nogrid labcolor(white)) ///
		xlab(, nogrid) ///
		graphregion(margin(l=-6 r=-5 t=-4 b=-4)) ///
		xtitle("") xscale(range(0 1)) xlabel(0 (0.2) 1, labsize(large)) ///	
		ytitle("") yscale(range(0 1)) ylabel(0 (0.2) 1, labsize(large)) ///	
		title("") ///
		text(.1 1 "`v'", size(vlarge) place(left)) ///
		legend(off)
}

	graph combine c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25, l1("Support for security/defence integration", size(small)) b1(Threat perception, size(small)) xcommon ycommon

